Ext.ns('App.login');
App.login.LoginWindow = Ext.extend(Ext.Panel, {
	constructor : function(_config) {
		if (Ext.isIE) {
			document.body.style.marginLeft = (document.body.offsetWidth - 1024)
					/ 2;
			document.body.style.marginTop = (document.body.offsetHeight - 768)
					/ 2;
		}
		if (_config == null) {
			_config = {};
		}

		Ext.apply(this, _config);

		App.login.LoginWindow.superclass.constructor.call(this, _config);

		Ext.QuickTips.init();

		this.pWidth = 1024;
		this.pHeight = 768;

		this.viewW = this.pWidth - 15;

		Ext.get("dddd").setWidth(this.viewW);

		this.viewH = this.pHeight - 20;

		this.form = new Ext.FormPanel({
			renderTo : 'dddd',
			id : 'iCLoginPanel',
			border : false,
			layout : 'absolute',
			width : this.viewW,
			height : this.viewH - 120,
			margins : 0,
			frame : true,
			html : "<img src='./commons/images/768.png' height='100%' width='100%'/>",
			items : [{
						xtype : 'textfield',
						x : 480,
						y : 310,
						name : 'userName',
						minLength : 2,
						maxLength : 30,
						maxLengthText : '用户名最大输入30个字符',
						width : 110,
						allowBlank : false,
						blankText : '用户名不能为空',
						anchor : '63%'
					}, {
						xtype : 'textfield',
						x : 480,
						y : 340,
						name : 'password',
						inputType : 'password',
						minLength : 3,
						maxLength : 20,
						maxLengthText : '密码最大输入20个字符',
						width : 110,
						allowBlank : false,
						blankText : '密码不能为空',
						anchor : '63%'
					}, new Ext.ux.ImageButton({
								imgPath : './commons/images/login.png',
								x : 400,
								y : 380,
								imgWidth : 110,
								imgHeight : 25,
								tooltip : '登录',
								handler : iCLogin
							}), new Ext.ux.ImageButton({
								imgPath : './commons/images/clear.png',
								x : 550,
								y : 380,
								imgWidth : 110,
								imgHeight : 25,
								tooltip : '重置',
								handler : function() {
									Ext.getCmp('iCLoginPanel').getForm()
											.reset();
								}
							})],
			listeners : {
				'render' : function(panel) {
					panel.body.on('keypress', function(e) {
								if (e.keyCode == 13)
									iCLogin();
							})
				}
			}
		});

	}
})

function iCLogin() {
	var loginForm = Ext.getCmp('iCLoginPanel').getForm();
	if (loginForm.isValid()) {
		loginForm.submit({
					waitTitle : '提示',
					waitMsg : '正在登录……',
					url : 'user/login',
					method : 'post',
					success : function(form, action) {
						if (action.result.success) {
							window.location.href = 'main.jsp';
						} else {
							Ext.Msg.alert('提示', '网络连接异常');
						}
					},
					failure : function(form, action) {
						Ext.Msg.alert('提示', action.result.info);
					}
				})
	}
}
